﻿using System;
using System.ComponentModel;

namespace SharePointUtilitiesForDevelopers
{
    /// <summary>
    /// A domain class that represents a SharePoint CAML query order by expression.
    /// </summary>
    [ReadOnly(true)]
    public class SharePointQueryOrderByExpression
    {
        private readonly string _fieldStaticName;
        private readonly bool _sortAscending = true;

        /// <summary>
        /// Initializes a new instance of the <see cref="SharePointQueryOrderByExpression"/> class.
        /// </summary>
        /// <param name="fieldStaticName">The field static name.</param>
        /// <param name="sortAscending">The sort direction.</param>
        public SharePointQueryOrderByExpression(string fieldStaticName, bool sortAscending)
        {
            if (string.IsNullOrEmpty(fieldStaticName))
            {
                throw new ArgumentNullException("fieldStaticName");
            }

            _fieldStaticName = fieldStaticName;
            _sortAscending = sortAscending;
        }
        
        /// <summary>
        /// Gets or sets the field static name.
        /// </summary>
        /// <value>The field static name.</value>
        [Description("The field to order by.")]
        public string FieldStaticName
        {
            get { return _fieldStaticName; }
        }

        /// <summary>
        /// Gets a value indicating whether to sort ascending.
        /// </summary>
        /// <value><c>true</c> if sort ascending; otherwise, <c>false</c>.</value>
        [Description("Indicates if the field is sorted ascending.")]
        public bool SortAscending
        {
            get { return _sortAscending; }
        }
    }
}
